package com.tgy.demo;

import jdk.nashorn.internal.ir.CallNode;

import java.sql.*;

/***
 * @ClassName: JdbcFirstDemo
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 20:10 2021/11/29
 * @version : V1.0
 */
public class JdbcFirstDemo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1、加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2、用户信息和url
        String url = "jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&charcaterEncoding=useSSL=ture";
        String username = "root";
        String password = "123456";

        //3、连接成功，数据库对象
        Connection connection = DriverManager.getConnection(url, username, password);

        //4、执行SQL的对象
        Statement statement = connection.createStatement();

        //5、执行SQL的对象去执行SQL,可能存在结果，查看返回结果
        String sql = "SELECT * FROM `users`";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()){
            System.out.println(resultSet.getString("name"));

        }
        //6、释放连接
        resultSet.close();
        statement.close();
        connection.close();


    }
}
